package com.globallogic.model.service;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

import com.globallogic.model.dao.DailyPlanDao;
import com.globallogic.model.entity.DailyPlan;
import com.globallogic.model.transferobject.DailyPlanTo;

@Stateless
public class DailyPlanService {

	@TransactionAttribute(TransactionAttributeType.REQUIRED)
	public List<DailyPlan> getDailyPlans() {
		return dailyPlanDao.getAll();
	}

	@TransactionAttribute(TransactionAttributeType.REQUIRED)
	public boolean createDailyPlan(DailyPlan dailyPlan) {

		dailyPlanDao.insert(dailyPlan);
        return true;
        
	}
	
	@TransactionAttribute(TransactionAttributeType.REQUIRED)
	public boolean updateDailyPlan(DailyPlan dailyPlan) {
        
		dailyPlanDao.update(dailyPlan);
        return true;
        
	}	

	@TransactionAttribute(TransactionAttributeType.REQUIRED)
	public void deleteDailyPlan(int id) {

		dailyPlanDao.delete(id);
        
	}
	
	@TransactionAttribute(TransactionAttributeType.REQUIRED)
	public DailyPlanTo getDailyPlanById(int Id) {
		DailyPlan dailyPlan = dailyPlanDao.getById(Id); 
		
		return dailyPlan.getTo();
	}

	@EJB
	private DailyPlanDao dailyPlanDao;

}
